package com.uex.dev.manage.admin.controller;

import com.google.common.base.Preconditions;
import com.uex.dev.manage.admin.po.ProjectFilesPO;
import com.uex.dev.manage.admin.po.ProjectOrderPO;
import com.uex.dev.manage.admin.po.ProjectPO;
import com.uex.dev.manage.admin.po.ProjectVersionPO;
import com.uex.dev.manage.admin.service.IProjectFilesService;
import com.uex.dev.manage.admin.service.IProjectOrderService;
import com.uex.dev.manage.admin.service.IProjectService;
import com.uex.dev.manage.admin.service.IProjectVersionService;
import com.uex.dev.manage.admin.vo.project.*;
import com.uex.dev.manage.common.base.ModelResult;
import com.uex.dev.manage.common.base.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * @author lzs
 * @create 2024/02/23
 * @description
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@Tag(name = "项目管理")
@RequestMapping("/project")
@RestController
public class ProjectController {

    @Resource
    private IProjectService projectService;

    @Resource
    private IProjectFilesService projectFilesService;

    @Resource
    private IProjectVersionService projectVersionService;

    @Resource
    private IProjectOrderService projectOrderService;

//    @Operation(description = "设备项目列表")
//    @PostMapping("/page")
//    public ModelResult<PageResult<ProjectPageResp>> projectPage(@RequestBody ProjectPageReq projectPageReq) {
//        return new ModelResult<>(projectService.pageProject(projectPageReq));
//    }

    @Operation(description = "获取项目列表")
    @GetMapping("/list")
    public ModelResult<PageResult<ProjectListResp>> getProjectList(ProjectListReq projectListReq) {
        return new ModelResult<>(projectService.getProjectList(projectListReq));
    }

    @Operation(description = "查看项目信息")
    @GetMapping("/info")
    public ModelResult<ProjectInfo> getPrjInfo(@RequestParam Integer prjId) {
        return new ModelResult<>(projectService.getPrjInfo(prjId));
    }

    @Operation(description = "添加或修改项目信息")
    @PostMapping("/info")
    public ModelResult updatePrjInfo(@RequestBody ProjectPO projectUpdateInfoReq) {
        projectService.updatePrjInfo(projectUpdateInfoReq);
        return ModelResult.SUCCESS_RESULT;
    }

    @Operation(description = "查看项目版本")
    @GetMapping("/version")
    public ModelResult<ProjectVersionResp> getPrjVersion(@RequestParam Integer prjId, @RequestParam Integer id) {
        Preconditions.checkArgument(Objects.nonNull(prjId), "项目Id不能为空");
        return new ModelResult<>(projectVersionService.getPrjVersion(prjId, id));
    }

    @Operation(description = "添加或更新项目版本记录")
    @PostMapping("/version")
    public ModelResult updatePrjVersion(@RequestBody ProjectVersionPO projectVerUpdateReq) {
        projectVersionService.updatePrjVersion(projectVerUpdateReq);
        return ModelResult.SUCCESS_RESULT;
    }

    @Operation(description = "查看项目版本更新列表")
    @GetMapping("/verlist")
    public ModelResult<List<ProjectVerListResp>> getPrjVerList(@RequestParam Integer prjId) {
        Preconditions.checkArgument(Objects.nonNull(prjId), "项目Id不能为空");
        return new ModelResult<>(projectVersionService.getPrjVerList(prjId));
    }

    @Operation(description = "查看项目文档")
    @GetMapping("/file")
    public ModelResult<List<ProjectFileResp>> getProjectFiles(@RequestParam Integer prjId) {
        Preconditions.checkArgument(Objects.nonNull(prjId), "项目Id不能为空");
        return new ModelResult<>(projectFilesService.getProjectFiles(prjId));
    }

    @Operation(description = "添加项目文档")
    @PostMapping("/file")
    public ModelResult addProjectFile(@RequestBody ProjectFilesPO projectAddFileReq) {
        return projectFilesService.addProjectFile(projectAddFileReq) ? ModelResult.SUCCESS_RESULT : ModelResult.SYSTEM_ERROR_RESULT;
    }

    @Operation(description = "删除项目文档")
    @DeleteMapping("/file")
    public ModelResult delProjectFile(@RequestParam Integer id) {
        Preconditions.checkArgument(Objects.nonNull(id), "项目文档Id不能为空");
        projectFilesService.delProjectFile(id);
        return ModelResult.SUCCESS_RESULT;
    }

    @Operation(description = "设备维保购买")
    @PostMapping("/order")
    public ModelResult<?> orderProject(@RequestBody ProjectOrderPO projectOrderReq) {
        Preconditions.checkArgument(Objects.nonNull(projectOrderReq.getPrjid()), "项目Id不能为空");
        Preconditions.checkArgument(Objects.nonNull(projectOrderReq.getStartTime()), "开始时间不能为空");
        Preconditions.checkArgument(Objects.nonNull(projectOrderReq.getEndTime()), "结束时间不能为空");
        return projectOrderService.orderProject(projectOrderReq) ? ModelResult.SUCCESS_RESULT : ModelResult.SYSTEM_ERROR_RESULT;
    }
}

